﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MediatR;
using SystemHYS.API.Application.command.GualityGroupCommand;
using SystemHYS.API.DTOS;
using SystemHYS.Domian.DTO;
using SystemHYS.Domian;
using SystemHYS.API.Application.command.GualityProjectCommand;
using Microsoft.AspNetCore.Authorization;
namespace SystemHYS.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [Authorize]
    [ApiController]
    public class GualityProjectController : ControllerBase
    {
        IMediator mediator;
        public GualityProjectController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 获取质检项目信息
        /// </summary>
        /// <param name="command">查询条件</param>
        /// <returns>返回质检项目信息</returns>
        [HttpGet]
        public async Task<Apiresult<PageDTO<GualityProject>>> GetGualityProject([FromQuery] GualityProjectShowCommand command)
        {
            Apiresult<PageDTO<GualityProject>> apiresult = new Apiresult<PageDTO<GualityProject>>();
            try
            {
                apiresult.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                apiresult.Code = -1;
                apiresult.Message = ex.Message;
                throw;
            }
            return apiresult;
        }
        /// <summary>
        /// 添加质检项目信息
        /// </summary>
        /// <param name="command">质检项目信息</param>
        /// <returns>返回受影响信息</returns>
        [HttpPost]
        public async Task<Apiresult<int>> AddGualityProject(GualityProjectCreateCommand command)
        {
            Apiresult<int> apiresult = new Apiresult<int>();
            try
            {
                apiresult.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                apiresult.Code = -1;
                apiresult.Message = ex.Message;
                throw;
            }
            return apiresult;
        }
        /// <summary>
        /// 删除质检项目信息
        /// </summary>
        /// <param name="command">质检项目id</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public async Task<Apiresult<int>> DeleteGualityProject(GualityProjectDeleteCommand command)
        {
            Apiresult<int> apiresult = new Apiresult<int>();
            try
            {
                apiresult.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                apiresult.Code = -1;
                apiresult.Message = ex.Message;
                throw;
            }
            return apiresult;
        }
        /// <summary>
        /// 获取质检项目信息
        /// </summary>
        /// <param name="command">质检项目id</param>
        /// <returns>返回质检项目</returns>
        [HttpGet]
        public async Task<Apiresult<GualityProject>> ModelGualityProject([FromQuery] GualityProjectModelCommand command)
        {
            Apiresult<GualityProject> apiresult = new Apiresult<GualityProject>();
            try
            {
                apiresult.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                apiresult.Code = -1;
                apiresult.Message = ex.Message;
                throw;
            }
            return apiresult;
        }
        /// <summary>
        /// 修改质检项目
        /// </summary>
        /// <param name="command">质检项目信息</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public async Task<Apiresult<int>> UpdateGualityProject(GualityProjectUpdateCommand command)
        {
            Apiresult<int> apiresult = new Apiresult<int>();
            try
            {
                apiresult.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                apiresult.Code = -1;
                apiresult.Message = ex.Message;
                throw;
            }
            return apiresult;
        }
    }
}
